<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Special extends WD_Controller {

    public function index(){

        $host = \libraries\waydiao\Wdata::getHost();

        $treeData = \libraries\waydiao\Wdata::getTreeData();

        $data = [
            'host' => $host,
            'treeData' => $treeData,
        ];

        $this->load->view('special/index', $data);
    }

	/**
	 * API
	 */
	public function coinPurchaseNotifyAlipay(){

		$data = [

		];

		$this->load->view('special/coinPurchaseNotifyAlipay', $data);

	}

    /**
     * 微信支付回调
     */
	public function coinPurchaseNotifyWechat(){
	    if(empty($_POST)){
            $this->load->view('special/coinPurchaseNotifyWechat', []);
        }else{
            $url = isset($_POST["url"]) ? $_POST["url"] : "";
            $jsonstr = isset($_POST["jsonstr"]) ? $_POST["jsonstr"] : "";

            if($jsonarr = json_decode($jsonstr, true)){
                $xml = "<xml>";
                foreach ($jsonarr as $key=>$val){
                    if (is_numeric($val)){
                        $xml.="<".$key.">".$val."</".$key.">";
                    }else{
                        $xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
                    }
                }
                $xml.="</xml>";
                try{
                    $context = stream_context_create([
                        'http' => [
                            'method' => 'POST',
                            'header' => 'Content-type:application/x-www-form-urlencoded',
                            'content' => $xml,
                            'timeout' => 20
                        ]
                    ]);
                    $text = file_get_contents($url, false, $context);
                    echo $text;
                }catch (\Exception $e){
                    print_r($e->getMessage());
                }
            }
        }

	}


}
